
Program Select

! list of line numbers from AP,MAT,SRT files by
! input coordinates
!
! read std. input like this:
!        pluto.MAT
!        100 100
!        150 100
!
  character(len=500) :: name,radek
  integer, parameter :: MAXSTARS = 10000
  real, parameter :: TOL = 10.0
  real :: xi(MAXSTARS),yi(MAXSTARS),x,y
  integer :: No,n,i,line
  logical :: found

! file
  read(*,"(A)") name

! coordinates
  do i = 1, MAXSTARS
     read(*,*,end=10) xi(i),yi(i)
  enddo
10 n = i - 1

  do i = 1, n
!    write(*,*) " :",xi(i),yi(i),":"
    open(11,file=name,status='old',iostat=k)
    if( k /= 0 ) stop 'File not found.'

    line = 0
    found = .false.
    do
       line = line + 1
       read(11,"(i6,14f9.3)",end=99,iostat=k) No,x,y 
!       write(*,*) line,">",x,y,(xi(i) - x)**2 + (yi(i) - y)**2
       if( k == 0 )then
          if( (xi(i) - x)**2 + (yi(i) - y)**2 < TOL ) then
             write(*,"(I4,' ')",advance="no") line
!             write(*,*) line,x,y,xi(i),yi(i)
             found = .true.
             exit
          endif
       endif
    enddo
99  close(11)
    if( .not. found ) write(*,*) " !Star at ",xi(i),yi(i)," not found! "

enddo

end program


